home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 December / Australian PC User - December 2003 (CD2).iso / software / apps / files / dwmx2k4.exe / Disk1 / data1.cab / Configuration_En / Commands / ServerObject-FormCmnASPNet.js < prev    next >
Encoding:
JavaScript  |  2003-09-05  |  46.4 KB  |  1,721 lines

  1. // Copyright 2002, 2003 Macromedia, Inc. All rights reserved.
  2.     
  3. //**********************GLOBAL VARS********************
  4.  
  5. var TEXTFIELD        =  MM.LABEL_TextField;
  6. var HIDDENFIELD        =  MM.LABEL_HiddenField;
  7. var PASSWORDFIELD    =  MM.LABEL_PasswordField;
  8. var PASSWORD        =  MM.LABEL_Password;
  9. var FILEFIELD        =  MM.LABEL_FileField;
  10. var TEXTAREA        =  MM.LABEL_TextArea;
  11. var MENU            =  MM.LABEL_Menu;
  12. var CHECKBOX        =  MM.LABEL_CheckBox;
  13. var RADIOGROUP        =  MM.LABEL_RadioGroup;
  14. var STATICTEXT        =  MM.LABEL_Text;
  15.  
  16. var STR_DIVIDER = "* *";
  17. var STR_ELEMENT_NAMES = STR_DIVIDER;
  18.  
  19. var DB_UNSUPPORTED_COLUMNS_ENUM_MAP = null;
  20.  
  21. //--------------------------------------------------------------------
  22. // FUNCTION:
  23. //   createFormElementStrings
  24. //
  25. // DESCRIPTION:
  26. //   This function creates the form element strings that will be used
  27. //   to create the final form.
  28. //
  29. // ARGUMENTS:
  30. //   none
  31. //
  32. // RETURNS:
  33. //   nothing
  34. //--------------------------------------------------------------------
  35.  
  36. function createFormElementStrings(rowInfoArr)
  37. {
  38.   var nRows = rowInfoArr.length;
  39.   var formElemStrArr = new Array();
  40.  
  41.   for (var i = 0; i < nRows; i++)
  42.   {
  43.     var currRowInfoObj = rowInfoArr[i];
  44.     var fieldInfoObj = currRowInfoObj.displayAs; 
  45.     
  46.     fieldInfoObj.fieldName = currRowInfoObj.fieldName;
  47.     
  48.     var fieldLabel = currRowInfoObj.label;    
  49.     var fieldVal = fieldInfoObj.value;         
  50.     var fieldType = fieldInfoObj.type;
  51.     
  52.     var formElemObj = new Object();    
  53.     
  54.     formElemObj.ElementName = fieldInfoObj.fieldName;
  55.     formElemObj.ElementType = fieldType.toLowerCase();
  56.     formElemObj.ElementValue = fieldVal;
  57.     formElemObj.ElementLabel = fieldLabel;
  58.     formElemObj.EqualToVal = "";
  59.     formElemObj.UseWebFormControl = currRowInfoObj.useWebFormControl;
  60.  
  61.     if (fieldType == "text")
  62.     {
  63.       formElemObj.ElementValue = fieldInfoObj.text;
  64.     }
  65.     else if (fieldType == "checkBox")
  66.     {
  67.       if (fieldInfoObj.checked)
  68.       {
  69.         formElemObj.ElementChecked = "checked";
  70.         formElemObj.CheckedState = "true";
  71.       }
  72.       else
  73.       {
  74.         formElemObj.ElementChecked = "";
  75.         formElemObj.CheckedState = "false";
  76.       }
  77.     }
  78.     else if (fieldType == "dynamicCheckBox")
  79.     {  
  80.       if (fieldInfoObj.checkIf)
  81.       {
  82.         var trueValue = fieldInfoObj.equalTo;
  83.  
  84.         // Add quotes if none
  85.  
  86.         if ((trueValue.charAt(0) != "'") && (trueValue.charAt(0) != '"'))
  87.         {
  88.           trueValue = '"' + trueValue + '"';
  89.         }
  90.  
  91.         var checkIf = fieldInfoObj.checkIf;
  92.  
  93.         // If the conditional is surrounded by script tags, remove them
  94.  
  95.         var re = /<%#\s*([\s\S]+)\s*%>/ig
  96.         var attrib;
  97.  
  98.         while ((attrib = re.exec(checkIf)) != null)
  99.         {
  100.           checkIf = checkIf.replace(attrib[0], attrib[1]);
  101.         }
  102.  
  103.         checkIf = "(" + dwscripts.getEqualsStatement(checkIf, trueValue) + ")";
  104.  
  105.         formElemObj.ElementValue = trueValue;
  106.         formElemObj.ElementChecked = "<%# " + dwscripts.getTernaryStatement(checkIf, "\"checked\"", "\"\"") + " %>";
  107.         formElemObj.CheckedState = "<%# " + dwscripts.getTernaryStatement(checkIf, "true", "false") + " %>";
  108.       }
  109.       else
  110.       {
  111.         formElemObj.ElementChecked = "";
  112.         formElemObj.CheckedState = "false";
  113.       }
  114.     }
  115.     else if (fieldType == "menu")
  116.     {
  117.       var nOptions = fieldInfoObj.textArr.length;
  118.       var defaultSelected = fieldInfoObj.defaultSelected;
  119.       
  120.       // If the selected value code is surrounded by script tags, remove them
  121.       // If it's not, then make sure it's surrounded by quotes.
  122.  
  123.       var re = /<%#\s*([\s\S]+)\s*%>/ig
  124.       var attrib = re.exec(defaultSelected);
  125.  
  126.       if (attrib != null)
  127.       {
  128.         do
  129.         {
  130.           defaultSelected = defaultSelected.replace(attrib[0], attrib[1]);
  131.         }
  132.         while (attrib == re.exec(defaultSelected));
  133.       }
  134.       else if (defaultSelected.charAt(0) != '"')
  135.       {
  136.         defaultSelected = "\"" + defaultSelected + "\"";
  137.       }
  138.  
  139.       // Replace instances of "Container" with null
  140.  
  141.       defaultSelected = defaultSelected.replace(/Container/g, dwscripts.getNullToken());
  142.  
  143.       if (!nOptions) 
  144.       {
  145.          var labelText = "[ " + MM.LABEL_Label + " ]";
  146.  
  147.          fieldInfoObj.textArr = new Array(labelText, labelText);
  148.          fieldInfoObj.valArr   = new Array("menuitem1","menuitem2");
  149.          nOptions = 2;
  150.       }      
  151.       
  152.       formElemObj.OptionText = fieldInfoObj.textArr;
  153.       formElemObj.OptionValue = fieldInfoObj.valArr;
  154.       formElemObj.SelectedValue = defaultSelected;
  155.  
  156.       // This logic checks if the selected field is same as the value,
  157.       // if so marks it as selected, otherwise adds an empty string.
  158.       // this logic is required because all the arrays should be of same
  159.       // length for loop in edml file
  160.  
  161.       var optionSelectedArr = new Array();
  162.  
  163.       for (var j = 0; j < nOptions; j++)
  164.       {
  165.         if (fieldInfoObj.valArr[j] && defaultSelected)
  166.         {
  167.           var selObj = new Object;
  168.  
  169.           selObj.DefaultSelected = defaultSelected;
  170.           selObj.ItemValue = fieldInfoObj.valArr[j];
  171.  
  172.           // If ItemValue doesn't have quotes, add them
  173.  
  174.           if (selObj.ItemValue.charAt(0) != '"')
  175.           {
  176.             selObj.ItemValue = "\"" + selObj.ItemValue + "\"";
  177.           }
  178.  
  179.           optionSelectedArr.push(extPart.getInsertString("", "Menu_OptionSelected", selObj, ""));
  180.         }
  181.         else
  182.         {
  183.           optionSelectedArr.push("");
  184.         }
  185.       }
  186.  
  187.       formElemObj.OptionSelected = optionSelectedArr;
  188.     }
  189.     else if (fieldType == "radioGroup")
  190.     {
  191.       var nButtons = fieldInfoObj.labelArr.length;
  192.       var defaultChecked = fieldInfoObj.defaultChecked;
  193.       
  194.       // If the selected value code is surrounded by script tags, remove them
  195.       // If it's not, then make sure it's surrounded by quotes.
  196.  
  197.       var re = /<%#\s*([\s\S]+)\s*%>/ig
  198.       var attrib = re.exec(defaultChecked);
  199.  
  200.       if (attrib != null)
  201.       {
  202.         do
  203.         {
  204.           defaultChecked = defaultChecked.replace(attrib[0], attrib[1]);
  205.         }
  206.         while (attrib == re.exec(defaultChecked));
  207.       }
  208.       else if (defaultChecked.charAt(0) != '"')
  209.       {
  210.         defaultChecked = "\"" + defaultChecked + "\"";
  211.       }
  212.  
  213.       // Replace instances of "Container" with null
  214.  
  215.       defaultChecked = defaultChecked.replace(/Container/g, dwscripts.getNullToken());
  216.  
  217.       if (!nButtons) 
  218.       {
  219.          var labelText = "[ " + MM.LABEL_Label + " ]";
  220.  
  221.          fieldInfoObj.labelArr = new Array(labelText, labelText);
  222.          fieldInfoObj.valArr   = new Array("radiobutton1","radiobutton2");
  223.          nButtons = 2;
  224.       }
  225.       
  226.       formElemObj.OptionText = fieldInfoObj.labelArr;
  227.       formElemObj.OptionValue = fieldInfoObj.valArr;
  228.       formElemObj.SelectedValue = defaultChecked;
  229.  
  230.       // This logic checks if the selected field is same as the value,
  231.       // if so marks it as selected, otherwise adds an empty string.
  232.       // this logic is required because all the arrays should be of same
  233.       // length for loop in edml file
  234.  
  235.       var optionSelectedArr = new Array();
  236.  
  237.       for (var j = 0; j < nButtons; j++)
  238.       {
  239.         if (fieldInfoObj.valArr[j] && defaultChecked)
  240.         {
  241.           var selObj = new Object;
  242.  
  243.           selObj.DefaultChecked = defaultChecked;
  244.           selObj.ItemValue = fieldInfoObj.valArr[j];
  245.  
  246.           // If ItemValue doesn't have quotes, add them
  247.  
  248.           if (selObj.ItemValue.charAt(0) != '"')
  249.           {
  250.             selObj.ItemValue = "\"" + selObj.ItemValue + "\"";
  251.           }
  252.  
  253.           optionSelectedArr.push(extPart.getInsertString("", "Radio_OptionChecked", selObj, ""));
  254.         }
  255.         else
  256.         {
  257.           optionSelectedArr.push("\"FALSE\"");
  258.         }
  259.       }
  260.  
  261.       formElemObj.OptionSelected = optionSelectedArr;
  262.     }
  263.     else if (fieldType == "dynamicMenu")
  264.     {
  265.       var defaultSelected = fieldInfoObj.defaultSelected;
  266.       
  267.       // If the selected value code is surrounded by script tags, remove them
  268.       // If it's not, then make sure it's surrounded by quotes.
  269.  
  270.       var re = /<%#\s*([\s\S]+)\s*%>/ig
  271.       var attrib = re.exec(defaultSelected);
  272.  
  273.       if (attrib != null)
  274.       {
  275.         do
  276.         {
  277.           defaultSelected = defaultSelected.replace(attrib[0], attrib[1]);
  278.         }
  279.         while (attrib == re.exec(defaultSelected));
  280.       }
  281.       else if (defaultSelected.charAt(0) != '"')
  282.       {
  283.         defaultSelected = "\"" + defaultSelected + "\"";
  284.       }
  285.  
  286.       // Replace instances of "Container" with null
  287.  
  288.       defaultSelected = defaultSelected.replace(/Container/g, dwscripts.getNullToken());
  289.  
  290.       formElemObj.DynOptionText = fieldInfoObj.textCol;
  291.       formElemObj.DynOptionValue = fieldInfoObj.valCol;
  292.  
  293.       var selObj = new Object;
  294.  
  295.       selObj.DefaultSelected = defaultSelected;
  296.       selObj.ItemValue = dwscripts.sprintf("%s.FieldValue(\"%s\", Container)", fieldInfoObj.recordset, fieldInfoObj.valCol);
  297.  
  298.       formElemObj.DynOptionSelected = extPart.getInsertString("", "Menu_OptionSelected", selObj, "");
  299.       formElemObj.RecordsetName = fieldInfoObj.recordset;
  300.       formElemObj.SelectedValue = defaultSelected;
  301.     }
  302.     else if (fieldType == "dynamicRadioGroup")
  303.     {
  304.       var defaultChecked = fieldInfoObj.defaultChecked;
  305.       
  306.       // If the selected value code is surrounded by script tags, remove them
  307.       // If it's not, then make sure it's surrounded by quotes.
  308.  
  309.       var re = /<%#\s*([\s\S]+)\s*%>/ig
  310.       var attrib = re.exec(defaultChecked);
  311.  
  312.       if (attrib != null)
  313.       {
  314.         do
  315.         {
  316.           defaultChecked = defaultChecked.replace(attrib[0], attrib[1]);
  317.         }
  318.         while (attrib == re.exec(defaultChecked));
  319.       }
  320.       else if (defaultChecked.charAt(0) != '"')
  321.       {
  322.         defaultChecked = "\"" + defaultChecked + "\"";
  323.       }
  324.  
  325.       // Replace instances of "Container" with null
  326.  
  327.       defaultChecked = defaultChecked.replace(/Container/g, dwscripts.getNullToken());
  328.  
  329.       formElemObj.DynOptionText = fieldInfoObj.labelCol;
  330.       formElemObj.DynOptionValue = fieldInfoObj.valCol;
  331.  
  332.       var selObj = new Object;
  333.  
  334.       selObj.DefaultChecked = defaultChecked;
  335.       selObj.ItemValue = dwscripts.sprintf("%s.FieldValue(\"%s\", Container)", fieldInfoObj.recordset, fieldInfoObj.valCol);
  336.  
  337.       formElemObj.DynOptionSelected = extPart.getInsertString("", "Radio_OptionChecked", selObj, "");
  338.       formElemObj.RecordsetName = fieldInfoObj.recordset;
  339.       formElemObj.SelectedValue = defaultChecked;
  340.     }
  341.  
  342.     //  There is some conditional logic in the downstream edml files that must check
  343.     //  the length of the SelectedValue.  Because the conditional edml system must always
  344.     //  find some value for elements it uses within conditions, we have to be sure something
  345.     //  is always set.
  346.  
  347.     formElemObj.SelectedValue = formElemObj.SelectedValue ? formElemObj.SelectedValue : "";
  348.  
  349.     formElemStrArr.push(extPart.getInsertString("", "EditOp-FormElement", formElemObj, ""));
  350.   }
  351.   
  352.   return formElemStrArr;
  353. }
  354.  
  355. //--------------------------------------------------------------------
  356. // FUNCTION:
  357. //   populateColumnGrid
  358. //
  359. // DESCRIPTION:
  360. //   This function is called by updateUI function.  It is responsible
  361. //   for populating the Column grid.
  362. //
  363. // ARGUMENTS:
  364. //   none
  365. //
  366. // RETURNS:
  367. //   nothing
  368. //--------------------------------------------------------------------
  369.  
  370. function populateColumnGrid()
  371. {
  372.   // clear additional column list
  373.   // it lists columns that don't get populated in the grid, and needs to be cleared
  374.   
  375.   updateAdditionalColumnList('clear'); 
  376.     
  377.   // if there are no tables, then clear grid
  378.   
  379.   if (!connectionHasBeenChosen())
  380.   {
  381.     _ColumnNames.setAllRows(new Array(), new Array());
  382.     return;
  383.   }
  384.  
  385.   //var colsAndTypes = MMDB.getColumnAndTypeOfTable(_ConnectionName.getValue(), _TableName.getValue());
  386.   var columnInfo = dwscripts.getColumnValueList(_ConnectionName.getValue(), _TableName.getValue());
  387.   var rowTextArr = new Array();
  388.   var rowValArr  = new Array();
  389.   
  390.   ColumnTypes = new Array();  // clear the column types map
  391.  
  392.   //for (var i = 0; i < colsAndTypes.length; i+=2)
  393.   for (var i = 0; i < columnInfo.length; i++)
  394.   {
  395.     var columnName = columnInfo[i].getColumnName();
  396.     var columnType = columnInfo[i].getColumnType();
  397.  
  398.     ColumnTypes[columnName] = columnType;
  399.     
  400.     if (EDIT_OP_TYPE == "Update") 
  401.     {
  402.       rowInfo = getRowTextAndValue(columnName,
  403.                                    columnType,
  404.                                    _RecordsetName.getValue(),
  405.                                    _UniqueKeyColumn.getValue());
  406.  
  407.       if (columnInfo[i].getIsPrimaryKey() && !uniqueKeyColumnName)
  408.       {
  409.         uniqueKeyColumnName = columnName;
  410.       }
  411.     } 
  412.     else 
  413.     {  
  414.       rowInfo = getRowTextAndValue(columnName, columnType);
  415.     }
  416.     
  417.     rowTextArr.push(rowInfo[0]);
  418.     rowValArr.push(rowInfo[1]);
  419.   }
  420.  
  421.   _ColumnNames.setAllRows(rowTextArr, rowValArr);
  422.     
  423.   // clear global field names array (used to check for dupe field names)
  424.  
  425.   STR_ELEMENT_NAMES = STR_DIVIDER;    
  426. }
  427.  
  428. //--------------------------------------------------------------------
  429. // FUNCTION:
  430. //   checkForUnsupportedColumnTypes
  431. //
  432. // DESCRIPTION:
  433. //   This function checks if all the columns are supported or not,
  434. //   displaying a message
  435. //
  436. // ARGUMENTS:
  437. //   Boolean - to display alert message or not
  438. //
  439. // RETURNS:
  440. //   Nothing
  441. //--------------------------------------------------------------------
  442.  
  443. function checkForUnsupportedColumnTypes(displayMsg)
  444. {   
  445.   // check for the colTypes to make sure we support them, if not
  446.   // the flow is that they don't appear in the form fields grids,
  447.   // But we do display a message saying that they are not displayed,
  448.   // but the user can add them manually by clicking on the + button...
  449.  
  450.   var unsupportedColTypes = new Array();
  451.   var unsupportedColNames = new Array();
  452.   
  453.   for (var i = 0; i < _ColumnNames.valueList.length; i++)
  454.   {
  455.     var rowInfoObj = _ColumnNames.valueList[i];
  456.  
  457.     if (rowInfoObj && rowInfoObj.colType)
  458.     {
  459.       if (!isColTypeSupported(rowInfoObj.colType))
  460.       {
  461.         unsupportedColTypes.push(rowInfoObj.colType);
  462.         unsupportedColNames.push(rowInfoObj);
  463.       }
  464.     }
  465.   }  
  466.   
  467.   if (unsupportedColTypes.length && unsupportedColNames.length)
  468.   {
  469.     if (displayMsg)
  470.       alert(dwscripts.sprintf(MM.Msg_UnsupportedColumnsInTable, unsupportedColTypes));
  471.     for (var i = 0; i < unsupportedColNames.length; i++)
  472.     {
  473.       // select the row that is to be deleted...
  474.       _ColumnNames.pickRowValue(unsupportedColNames[i]);
  475.       deleteGridRow();    
  476.     }
  477.   }
  478.  
  479. }
  480.  
  481. //--------------------------------------------------------------------
  482. // FUNCTION:
  483. //   isColTypeSupported
  484. //
  485. // DESCRIPTION:
  486. //   This function returns if the colType is supported by UD or not.
  487. //
  488. // ARGUMENTS:
  489. //   colType - string - column type for update
  490. //
  491. // RETURNS:
  492. //   boolean
  493. //--------------------------------------------------------------------
  494.  
  495. function isColTypeSupported(colType)
  496. {
  497.   if (DB_UNSUPPORTED_COLUMNS_ENUM_MAP == null)
  498.   {
  499.     buildUnsupportedColumnsEnum();
  500.   }
  501.   
  502.   return (!DB_UNSUPPORTED_COLUMNS_ENUM_MAP[colType.toLowerCase()]);
  503. }
  504.  
  505. //--------------------------------------------------------------------
  506. // FUNCTION:
  507. //   buildUnsupportedColumnsEnum
  508. //
  509. // DESCRIPTION:
  510. //   This function returns if the colType is supported by UD or not.
  511. //
  512. // ARGUMENTS:
  513. //   colType - string - column type for update
  514. //
  515. // RETURNS:
  516. //   boolean
  517. //--------------------------------------------------------------------
  518.  
  519. function buildUnsupportedColumnsEnum()
  520. {
  521.   if (DB_UNSUPPORTED_COLUMNS_ENUM_MAP == null)
  522.   {
  523.     // TODO: read in from a configuration file
  524.   
  525.     var a = new Array();
  526.  
  527.     a["binary"] = 128; 
  528.     a["varbinary"] = 204;
  529.     a["longvarbinary"] = 204; 
  530.     a["longbinary"] = 205; // matched to longvarbinary
  531.  
  532.     // oracle
  533.  
  534.     a["raw"]  = 204;// Match it to Binary
  535.     a["nclob"]  = 204;//Match it to Binary
  536.     a["bfile"]  = 204;//Match it to Binary
  537.     a["ref cursor"] = 900; //Arbitrary ID Val
  538.     a["refcursor"] = 900;
  539.  
  540.     // SQL Server 7
  541.     
  542.     a["image"]  =  204 ;// binary
  543.  
  544.     DB_UNSUPPORTED_COLUMNS_ENUM_MAP = a;
  545.   }
  546. }
  547.  
  548. //--------------------------------------------------------------------
  549. // FUNCTION:
  550. //   getRowTextAndValue
  551. //
  552. // DESCRIPTION:
  553. //   This function returns the information for a row in the column table.
  554. //
  555. // ARGUMENTS:
  556. //   colName - string - column name
  557. //   colType - string - column type
  558. //   rsName  - string - (optional) recordset name, only needed for update
  559. //   uniqueColName - string - (optional) Unique Key Column, only needed
  560. //                            for update
  561. //
  562. // RETURNS:
  563. //   array of 2 values
  564. //--------------------------------------------------------------------
  565.  
  566. function getRowTextAndValue(colName, colType, rsName, uniqueColName)
  567. {
  568.   var retVal = new Array(2);
  569.   var colFieldType = "";
  570.   var colSubmitType = "";
  571.   var colSubmitName = "";
  572.   var colLabel = getLabelFromColumnName(colName);
  573.   var fieldName = getElementNameFromColumnName(colName);
  574.   
  575.   // if update, the unique key column should be a static text...
  576.   
  577.   if ((EDIT_OP_TYPE == "Update") && (colName == uniqueColName))
  578.   {
  579.     colFieldType = STATICTEXT;
  580.   }
  581.   else
  582.   {
  583.     // default to password display type if "password" appears in field name
  584.     
  585.     if (colName.toLowerCase().indexOf(PASSWORD) != (-1))
  586.     {
  587.       colFieldType = PASSWORDFIELD;
  588.     }
  589.     else
  590.     {
  591.       colFieldType = getFieldTypeFromColumnType(colType);
  592.     }
  593.   }
  594.   
  595.   var databaseType = MMDB.getDatabaseType(_ConnectionName.getValue());
  596.   var colSubmitType = dwscripts.getDBColumnTypeAsString(colType, databaseType);
  597.   var colSubmitName = colSubmitType;
  598.   var colDisplayAs = getFormFieldStorageObjectFromFormFieldType(colFieldType);
  599.   
  600.   // disable the _SubmitAs field if it is for the Primary Key column
  601.   
  602.   if ((EDIT_OP_TYPE == "Update") && (colName == uniqueColName))
  603.   {
  604.     UniqueColSubmitAs = colSubmitType;
  605.  
  606.     colSubmitType = "";  
  607.     colSubmitName = "";
  608.  
  609.     toggleSubmitAs(false);                  // enable or disable Submit As Menu
  610.     toggleLabelVisibility(colDisplayAs);    // enable or disable Label textfield
  611.   }
  612.   
  613.   var rowText = colName + "|" + colLabel + "|" + colFieldType + "|" + colSubmitName;
  614.   var rowValObj = new Object();
  615.  
  616.   rowValObj.column = colName;
  617.   rowValObj.label = colLabel;
  618.   rowValObj.displayAs = colDisplayAs;
  619.   rowValObj.submitAs = colSubmitType;
  620.   rowValObj.fieldName = fieldName;
  621.   rowValObj.defaultStr = "";
  622.   rowValObj.passwordStr = "";
  623.   rowValObj.colType = colType;
  624.   rowValObj.useWebFormControl = true;
  625.  
  626.   // populate storage object with any default values
  627.   
  628.   if ((EDIT_OP_TYPE == "Update") && (rowValObj.displayAs.type != "passwordField"))
  629.   {
  630.     var rs = (rsName) ? rsName : _RecordsetName.getValue();
  631.     rowValObj = populateFormFieldStorageType(rowValObj, rs, colName);
  632.   }
  633.  
  634.   retVal[0] = rowText;
  635.   retVal[1] = rowValObj;
  636.             
  637.   return retVal;
  638. }
  639.  
  640. //--------------------------------------------------------------------
  641. // FUNCTION:
  642. //   getLabelFromColumnName
  643. //
  644. // DESCRIPTION:
  645. //
  646. // ARGUMENTS:
  647. //
  648. // RETURNS:
  649. //   Nothing
  650. //--------------------------------------------------------------------
  651.  
  652. function getLabelFromColumnName(colName)
  653. {
  654.   return colName.charAt(0).toUpperCase() + colName.substring(1) + MM.LABEL_Delimiter;      
  655. }
  656.  
  657. //--------------------------------------------------------------------
  658. // FUNCTION:
  659. //   getElementNameFromColumnName
  660. //
  661. // DESCRIPTION:
  662. //
  663. // ARGUMENTS:
  664. //   col - string - the column name to create an element name from
  665. //
  666. // RETURNS:
  667. //   string -  the element name
  668. //--------------------------------------------------------------------
  669.  
  670. function getElementNameFromColumnName(col)
  671. {
  672.   var elemName = col;
  673.   var counter = 2;
  674.   var divider = STR_DIVIDER;
  675.  
  676.   // replace spaces with underscores
  677.  
  678.   elemName = elemName.replace(/ /g, "_");
  679.   
  680.   // strip out all characters that are not alpha-numeric, or underscores
  681.  
  682.   elemName = elemName.replace(/[^a-zA-Z_0-9]/g, "");
  683.   
  684.   // don't allow the first character to be numeric
  685.  
  686.   while (parseInt(elemName.charAt(0)) &&
  687.          parseInt(elemName.charAt(0)) == elemName.charAt(0))
  688.   {
  689.     elemName = elemName.substring(1);
  690.   }
  691.  
  692.   // in the unlikely case that no characters are left after the above,
  693.   // then name element generically as "element"
  694.  
  695.   if (elemName.length == 0)
  696.   {
  697.     elemName = MM.LABEL_Element;
  698.   }
  699.  
  700.   // ensure that name is not a dupe
  701.  
  702.   var tempName = elemName; 
  703.  
  704.   while (STR_ELEMENT_NAMES.indexOf(divider + elemName + divider) != (-1))
  705.   {
  706.     elemName = tempName + counter++;
  707.   }
  708.  
  709.   // add name to global names list
  710.   
  711.   STR_ELEMENT_NAMES += elemName + divider;
  712.  
  713.   // You can't have a web form control whose id is "id"
  714.  
  715.   if (elemName.toLowerCase() == "id")
  716.   {
  717.     elemName = "theID";
  718.   }
  719.  
  720.   return elemName;
  721. }
  722.  
  723. //--------------------------------------------------------------------
  724. // FUNCTION:
  725. //   getFieldTypeFromColumnType
  726. //
  727. // DESCRIPTION:
  728. //   This function returns the field type based on the given column type
  729. //
  730. // ARGUMENTS:
  731. //   colType - string - the column type returned from MMDB
  732. //
  733. // RETURNS:
  734. //   Nothing
  735. //--------------------------------------------------------------------
  736.  
  737. function getFieldTypeFromColumnType(colType)
  738. {
  739.   return (dwscripts.isBooleanDBColumnType(colType)) ? CHECKBOX : TEXTFIELD;
  740. }
  741.  
  742. //--------------------------------------------------------------------
  743. // FUNCTION:
  744. //   getFormFieldStorageObjectFromFormFieldType
  745. //
  746. // DESCRIPTION:
  747. //   This function returns a field storage object, based on the 
  748. //   given field type.
  749. //
  750. // ARGUMENTS:
  751. //   fieldType - string - the field type selected in the UI
  752. //
  753. // RETURNS:
  754. //   object
  755. //--------------------------------------------------------------------
  756.  
  757. function getFormFieldStorageObjectFromFormFieldType(fieldType)
  758. {
  759.   var retObj = "";
  760.  
  761.   if (fieldType == STATICTEXT)
  762.   {
  763.     retObj = new eoText();
  764.   }
  765.   else if (fieldType == TEXTFIELD)
  766.   {
  767.     retObj = new eoTextField();
  768.   }
  769.   else if (fieldType == HIDDENFIELD)
  770.   {
  771.     retObj = new eoHiddenField();
  772.   }
  773.   else if (fieldType == PASSWORDFIELD)
  774.   {
  775.     retObj = new eoPasswordField();
  776.   }
  777.   else if (fieldType == FILEFIELD)
  778.   {
  779.     retObj = new eoFileField();
  780.   }
  781.   else if (fieldType == TEXTAREA)
  782.   {
  783.     retObj = new eoTextArea();
  784.   }
  785.   else if (fieldType == MENU)
  786.   {
  787.     retObj = new eoMenu();
  788.   }
  789.   else if (fieldType == RADIOGROUP)
  790.   {
  791.     retObj = new eoRadioGroup();
  792.   }
  793.   else if (fieldType == CHECKBOX)
  794.   {
  795.     retObj = (EDIT_OP_TYPE == "Insert") ? new eoCheckBox() : new eoDynamicCheckBox();
  796.   } 
  797.  
  798.   return retObj;
  799. }
  800.  
  801. //--------------------------------------------------------------------
  802. // FUNCTION:
  803. //   displayGridFieldValues
  804. //
  805. // DESCRIPTION:
  806. //   This function is called when the user clicks on a new row in the 
  807. //   grid, changes the values of the UI fields to display the correct
  808. //   information
  809. //
  810. // ARGUMENTS:
  811. //   None
  812. //
  813. // RETURNS:
  814. //   Nothing
  815. //--------------------------------------------------------------------
  816.  
  817. function displayGridFieldValues()
  818.   // don't bother if grid is empty -- needed because this fn is also
  819.   // called when the connection or table changes
  820.  
  821.   if (_ColumnNames.list.length == 0)
  822.   {
  823.     _ElementLabel.value = "";
  824.   }
  825.   else
  826.   {
  827.     var currRowText = _ColumnNames.getRow();
  828.     var currRowVal  = _ColumnNames.getRowValue();
  829.     
  830.     var rowTextTokens = getTokens(currRowText, "|");
  831.  
  832.     // TODO: this should be taken from the record, not the display
  833.  
  834.     _ElementLabel.value = currRowVal.label;                // update label field
  835.     _DisplayAs.pickValue(rowTextTokens[2]);                // update display menu
  836.     _UseWebFormCtrl.setCheckedState(currRowVal.useWebFormControl);
  837.  
  838.     // if the column is the unique key, don't let the "display as" be changed away from "text".
  839.  
  840.     if (EDIT_OP_TYPE == "Update")
  841.     {
  842.         if (rowTextTokens[0] == uniqueKeyColumnName)
  843.         {
  844.             _DisplayAs.disable();
  845.         }
  846.         else
  847.         {
  848.             _DisplayAs.enable();
  849.         }
  850.     }
  851.  
  852.     // change UI at bottom of dialog, if relevent
  853.     // for instance, if prior row had displayAs = Text, but this row has displayAs = Menu
  854.     
  855.     showDifferentParams(); 
  856.  
  857.     if (dwscripts.findDOMObject("SubmitAs")) 
  858.     {
  859.       _SubmitAs.pickValue(currRowVal.submitAs); // update submit menu
  860.     }
  861.  
  862.     // fill in form parameters at bottom of UI
  863.     // note that in the case of radio or menu, there is nothing to fill in
  864.     
  865.     switch (currRowVal.displayAs.type)
  866.     {
  867.     case "text":
  868.       dwscripts.findDOMObject("Text").value = currRowVal.displayAs.text = currRowVal.defaultStr;
  869.       break;
  870.     case "textArea":
  871.     case "textField":
  872.     case "hiddenField":
  873.     case "fileField":
  874.       dwscripts.findDOMObject("SetValueTo").value = currRowVal.displayAs.value = currRowVal.defaultStr;
  875.       break;
  876.     case "passwordField":
  877.       dwscripts.findDOMObject("SetValueTo").value = currRowVal.displayAs.value = currRowVal.passwordStr;
  878.       break;
  879.     case "checkBox": 
  880.       // note: dwscripts.findDOMObject doesn't work with radios, so manual references are needed
  881.       var InitialStateRadios = document.forms[0].InitialState;
  882.       if (currRowVal.displayAs.checked.toString() == "true")
  883.       {
  884.         InitialStateRadios[0].checked = true; InitialStateRadios[1].checked = false;
  885.       }
  886.       else
  887.       {
  888.         InitialStateRadios[0].checked = false; InitialStateRadios[1].checked = true;
  889.       }
  890.       break;
  891.  
  892.     case "dynamicCheckBox":
  893.       dwscripts.findDOMObject("CheckIf").value = currRowVal.displayAs.checkIf;
  894.       dwscripts.findDOMObject("EqualTo").value = currRowVal.displayAs.equalTo;
  895.       break;
  896.  
  897.     case "default":
  898.       break; 
  899.     }
  900.   }
  901. }
  902.  
  903. //--------------------------------------------------------------------
  904. // FUNCTION:
  905. //   showDifferentParams
  906. //
  907. // DESCRIPTION:
  908. //   This function shows form field specific parameters at the bottom
  909. //   of the dialog for instance, shows "Menu Properties" button for 
  910. //   menu, value field for textfield, etc
  911. //
  912. // ARGUMENTS:
  913. //   displayDefaultStr - Column Name
  914. //
  915. // RETURNS:
  916. //   Nothing
  917. //--------------------------------------------------------------------
  918.  
  919. function showDifferentParams(displayDefaultStr)
  920. {
  921.   // don't bother if connection has not been chosen
  922.  
  923.   if (connectionHasBeenChosen())
  924.   {
  925.     var displayAs = _DisplayAs.getValue() ? _DisplayAs.getValue() : "none";
  926.     var tables = domUIPieces.getElementsByTagName("TABLE"), param, i;
  927.     var mmParamsTag = document.getElementsByTagName("mmParams").item(0);
  928.     var rowInfoObj = _ColumnNames.getRowValue();
  929.  
  930.     if (EDIT_OP_TYPE == "Update" && rowInfoObj.fieldName == _UniqueKeyColumn.getValue())
  931.     {
  932.       toggleSubmitAs(false);
  933.     }
  934.     else
  935.     {
  936.       toggleSubmitAsVisibility(displayAs); // enable or disable Submit As Menu
  937.       toggleLabelVisibility(displayAs);    // enable or disable Label textfield
  938.     }
  939.  
  940.     if ((displayAs == TEXTFIELD) ||
  941.         (displayAs == TEXTAREA) ||
  942.         (displayAs == HIDDENFIELD) ||
  943.         (displayAs == PASSWORDFIELD) ||
  944.         (displayAs == FILEFIELD))
  945.     {
  946.       param = "textField";
  947.     }
  948.     else if (displayAs == STATICTEXT)
  949.     {
  950.       param = "text";
  951.     }
  952.     else if (displayAs == RADIOGROUP)
  953.     {
  954.       param = "radio";
  955.     }
  956.     else if (displayAs == MENU)
  957.     {
  958.       param = "menu";
  959.     }
  960.     else if (displayAs == CHECKBOX)
  961.     {
  962.       param = (EDIT_OP_TYPE == "Insert") ? "checkBox" : "dynamicCheckBox";
  963.     }
  964.     else if (displayAs == "none")
  965.     {
  966.       param = "none";
  967.     }
  968.  
  969.     for (i = 0;i < tables.length; i++)
  970.     {
  971.       if (tables[i].name && tables[i].name == param)
  972.       {
  973.         mmParamsTag.innerHTML = tables[i].innerHTML;
  974.         break;
  975.       }
  976.     }
  977.  
  978.     // if display as equals text, text area, or text field, and the display as menu has
  979.     // just been changed, then display the default text for this column
  980.  
  981.     if (displayDefaultStr)
  982.     {
  983.       var rowInfoObj = _ColumnNames.getRowValue();
  984.       var defaultStr = _ColumnNames.getRowValue().defaultStr;
  985.       var passwordStr = _ColumnNames.getRowValue().passwordStr;
  986.  
  987.       if ((displayAs == TEXTFIELD) ||
  988.           (displayAs == TEXTAREA) ||
  989.           (displayAs == HIDDENFIELD) ||
  990.           (displayAs == FILEFIELD))
  991.       {
  992.         dwscripts.findDOMObject("SetValueTo").value = rowInfoObj.displayAs.value = defaultStr;  // set UI
  993.       }
  994.       else if (displayAs == PASSWORDFIELD)
  995.       {
  996.         dwscripts.findDOMObject("SetValueTo").value = rowInfoObj.displayAs.value = passwordStr;    // set UI
  997.       }
  998.       else if (displayAs == STATICTEXT)
  999.       {
  1000.         dwscripts.findDOMObject("Text").value = rowInfoObj.displayAs.text = defaultStr;    // set UI
  1001.       }
  1002.       else if (param == "dynamicCheckBox")
  1003.       {
  1004.         dwscripts.findDOMObject("CheckIf").value = rowInfoObj.displayAs.checkIf = defaultStr;
  1005.       }
  1006.     }
  1007.   }
  1008. }
  1009.  
  1010. //--------------------------------------------------------------------
  1011. // FUNCTION:
  1012. //   addGridRow
  1013. //
  1014. // DESCRIPTION:
  1015. //   This function is called if there are columns not already 
  1016. //   displayed in the grid pop up the "Add Columns" dialog, and allow
  1017. //   the user to add them
  1018. //
  1019. // ARGUMENTS:
  1020. //   None
  1021. //
  1022. // RETURNS:
  1023. //   Nothing
  1024. //--------------------------------------------------------------------
  1025.  
  1026. function addGridRow()
  1027. {
  1028.   // check to see if there are columns to add first
  1029.  
  1030.   if (ColumnsToAdd.length == 0)
  1031.   {
  1032.     alert(MM.MSG_NoMoreColumnsToAdd);
  1033.     return;
  1034.   }
  1035.  
  1036.   var addedCols = dwscripts.callCommand("Add Column.htm", ColumnsToAdd);
  1037.  
  1038.   if (!addedCols)
  1039.     return; // user clicked Cancel
  1040.   
  1041.   var nCols = addedCols.length,i, currCol, rowInfoArr;
  1042.  
  1043.   for (i=0;i<nCols;i++)
  1044.   {
  1045.     currCol = addedCols[i];
  1046.     rowInfoArr = getRowTextAndValue(currCol, ColumnTypes[currCol]);
  1047.   
  1048.     _ColumnNames.addRow(rowInfoArr[0], rowInfoArr[1]);
  1049.   
  1050.     updateAdditionalColumnList('del', currCol);
  1051.   }
  1052. }
  1053.  
  1054. //--------------------------------------------------------------------
  1055. // FUNCTION:
  1056. //   deleteGridRow
  1057. //
  1058. // DESCRIPTION:
  1059. //   This function is called when the user clicks the "-" image button
  1060. //
  1061. // ARGUMENTS:
  1062. //  None
  1063. //
  1064. // RETURNS:
  1065. //   Nothing
  1066. //--------------------------------------------------------------------
  1067.  
  1068. function deleteGridRow()
  1069. {
  1070.   var currRow = _ColumnNames.getRow();
  1071.   var currCol = currRow.substring(0,currRow.indexOf("|"));
  1072.   var nRows = _ColumnNames.list.length;
  1073.  
  1074.   if (nRows > 1)
  1075.   {
  1076.     updateAdditionalColumnList('add',currCol);
  1077.     _ColumnNames.delRow();
  1078.     displayGridFieldValues(); 
  1079.   }
  1080.   else
  1081.   {
  1082.     alert(MM.MSG_NeedOneColumnInList);
  1083.   }
  1084. }
  1085.  
  1086. //--------------------------------------------------------------------
  1087. // FUNCTION:
  1088. //   updateGridRow
  1089. //
  1090. // DESCRIPTION:
  1091. //   This function is called whenever the label, submitAs, or displayAs
  1092. //   fields are edited updates both the actual text display in the grid, 
  1093. //   and the object that stores the information about the display
  1094. //
  1095. // ARGUMENTS:
  1096. //   whichColumn: the parameter which has been edited -- displayAs, 
  1097. //   submitAs, or label
  1098. //
  1099. // RETURNS:
  1100. //   Nothing
  1101. //--------------------------------------------------------------------
  1102.  
  1103. function updateGridRow(whichColumn)
  1104. {
  1105.   // check that connection has been chosen before proceeding
  1106.  
  1107.   if (!connectionHasBeenChosen())
  1108.   {
  1109.     alert(MM.MSG_NoConnectionSelected);
  1110.     return;
  1111.   }
  1112.  
  1113.   var currRowObj  = _ColumnNames.getRowValue();
  1114.   var currRowText = _ColumnNames.getRow();
  1115.   var currColName = currRowText.substring(0, currRowText.indexOf("|"));
  1116.  
  1117.   // update grid row text
  1118.  
  1119.   var newRowText = currColName;
  1120.  
  1121.   newRowText += "|" + _ElementLabel.value;
  1122.   newRowText += "|" + _DisplayAs.get();
  1123.   newRowText += "|" + (dwscripts.findDOMObject("SubmitAs") ? _SubmitAs.get() : "");
  1124.    
  1125.    _ColumnNames.setRow(newRowText);
  1126.  
  1127.   // update object that stores information about grid row
  1128.   // this object is stored in a value attribute of the Grid object
  1129.   // these objects are stored in an array: GridObj.valueList
  1130.  
  1131.   switch (whichColumn)
  1132.   {
  1133.   case "label":
  1134.     currRowObj.label = _ElementLabel.value;
  1135.     break;
  1136.  
  1137.   case "submitAs":
  1138.     currRowObj.submitAs = _SubmitAs.getValue();
  1139.     break;
  1140.  
  1141.   case "useWebFormControl":
  1142.     currRowObj.useWebFormControl = _UseWebFormCtrl.getCheckedState();
  1143.     break;
  1144.  
  1145.   case "displayAs": 
  1146.     currRowObj.displayAs = getFormFieldStorageObjectFromFormFieldType(_DisplayAs.getValue());
  1147.   
  1148.     // need to update submit property, because changing displayAs menu can
  1149.     // auto-change submit type
  1150.     
  1151.     if (dwscripts.findDOMObject("SubmitAs"))
  1152.     {
  1153.       currRowObj.submitAs = _SubmitAs.getValue();
  1154.     }
  1155.  
  1156.     var defaultStr = currRowObj.defaultStr;
  1157.     var passwordStr = currRowObj.passwordStr;
  1158.     var fieldType = currRowObj.displayAs.type;
  1159.  
  1160.     if ((fieldType == "textField") ||
  1161.         (fieldType == "hiddenField") || 
  1162.         (fieldType == "fileField") ||
  1163.         (fieldType == "textArea"))
  1164.     {
  1165.       currRowObj.displayAs.value = defaultStr;
  1166.     }
  1167.     else if (fieldType == "passwordField")
  1168.     {
  1169.       currRowObj.displayAs.value = passwordStr;          
  1170.     }
  1171.     else if (fieldType == "text")
  1172.     {
  1173.       currRowObj.displayAs.text = defaultStr;
  1174.     }
  1175.     else if (fieldType == "menu")
  1176.     {
  1177.       currRowObj.displayAs.defaultSelected = defaultStr;
  1178.     }
  1179.     else if (fieldType == "radioGroup")
  1180.     {
  1181.       currRowObj.displayAs.defaultChecked = defaultStr;
  1182.     }
  1183.     else if (fieldType == "dynamicCheckBox")
  1184.     {
  1185.       currRowObj.displayAs.checkIf = defaultStr;
  1186.     }
  1187.     break;
  1188.  
  1189.   default:
  1190.     break;
  1191.   }
  1192. }
  1193.  
  1194. //--------------------------------------------------------------------
  1195. // FUNCTION:
  1196. //   popUpFormFieldPropertiesDialog
  1197. //
  1198. // DESCRIPTION:
  1199. //   It pops up the Radio or Menu Properties dialog, and passes in the 
  1200. //   current menu/radio storage object so that the dialog can be 
  1201. //   initialized correctly
  1202. //
  1203. // ARGUMENTS:
  1204. //   whichOne - String that can be "Radio" or "Menu"
  1205. //
  1206. // RETURNS:
  1207. //   Nothing
  1208. //--------------------------------------------------------------------
  1209.  
  1210. function popUpFormFieldPropertiesDialog(whichOne)
  1211. {
  1212.   var commandFileName = "ServerObject-" + whichOne + "Props.htm";
  1213.   var rowObj = _ColumnNames.getRowValue();
  1214.   var fieldInfoObj = dwscripts.callCommand(commandFileName,rowObj.displayAs)
  1215.  
  1216.   // note: use the "type" property on the menuInfoObj to see which
  1217.   // type of object was returned
  1218.   
  1219.   if (fieldInfoObj)
  1220.   {
  1221.     rowObj.displayAs = fieldInfoObj;
  1222.   }
  1223. }
  1224.  
  1225. //--------------------------------------------------------------------
  1226. // FUNCTION:
  1227. //   updateAdditionalColumnList
  1228. //
  1229. // DESCRIPTION:
  1230. //   The + button calls up an Add Columns dialog, allowing
  1231. //   the user to add additional columns to the list. When the Add Columns
  1232. //   dialog is called, it is populated with the "additional columns list".
  1233. //   This list is updated when a user adds or deletes a column from the UI.
  1234. //
  1235. // ARGUMENTS:
  1236. //   action - Action argument that can Add, Del or Clear
  1237. //   col    - Column
  1238. //
  1239. // RETURNS:
  1240. //   Nothing
  1241. //--------------------------------------------------------------------
  1242.  
  1243. function updateAdditionalColumnList(action, col)
  1244. {
  1245.   if (action == 'add')
  1246.   {
  1247.     ColumnsToAdd.push(col);
  1248.   }
  1249.   else if (action == 'clear')
  1250.   {
  1251.     ColumnsToAdd = new Array();
  1252.   }
  1253.   else
  1254.   { 
  1255.     // delete an item from additional column list
  1256.     
  1257.     for (var i = 0; i < ColumnsToAdd.length; i++)
  1258.     {
  1259.       if (ColumnsToAdd[i] == col)
  1260.       {
  1261.         ColumnsToAdd.splice(i,1);
  1262.         break;
  1263.       }
  1264.     }
  1265.   }
  1266. }
  1267.  
  1268. //--------------------------------------------------------------------
  1269. // FUNCTION:
  1270. //   connectionHasBeenChosen
  1271. //
  1272. // DESCRIPTION:
  1273. //   This function is called when the grid is populated, to choose a 
  1274. //   submit type based on the column type
  1275. //
  1276. // ARGUMENTS:
  1277. //   None
  1278. //
  1279. // RETURNS:
  1280. //   Nothing
  1281. //--------------------------------------------------------------------
  1282.  
  1283. function connectionHasBeenChosen()
  1284. {
  1285.   return (_ConnectionName.getValue());
  1286. }
  1287.  
  1288. //--------------------------------------------------------------------
  1289. // FUNCTION:
  1290. //   checkThatCursorIsNotInsideOfAForm
  1291. //
  1292. // DESCRIPTION:
  1293. //   Before inserting a form, check that cursor is not inside of 
  1294. //   an existing form. If it is, set IP location to be just after the form
  1295. //
  1296. // ARGUMENTS:
  1297. //   None
  1298. //
  1299. // RETURNS:
  1300. //   Nothing
  1301. //--------------------------------------------------------------------
  1302.  
  1303. function checkThatCursorIsNotInsideOfAForm()
  1304. {
  1305.   var dom = dw.getDocumentDOM();
  1306.   var formNode = findForm(dom);
  1307.  
  1308.   if (formNode)
  1309.   {
  1310.     // if inside of a form tag
  1311.     
  1312.     formArr = dom.nodeToOffsets(formNode);
  1313.     dom.setSelection(formArr[1] + 1, formArr[1] + 1);
  1314.   }
  1315. }
  1316.  
  1317. //--------------------------------------------------------------------
  1318. // FUNCTION:
  1319. //   findForm
  1320. //
  1321. // DESCRIPTION:
  1322. //   Before inserting a form, check that cursor is not inside of 
  1323. //   an existing form. If it is, set IP location to be just after the form
  1324. //
  1325. // ARGUMENTS:
  1326. //   dom - DOM object
  1327. //
  1328. // RETURNS:
  1329. //   formObj
  1330. //--------------------------------------------------------------------
  1331.  
  1332. function findForm(dom)
  1333. {
  1334.   var formObj = "";
  1335.   var selArr = dom.getSelection();
  1336.   var selObj = dom.offsetsToNode(selArr[0], selArr[1]);
  1337.  
  1338.   while (formObj == "" && selObj.parentNode)
  1339.   {
  1340.     if (selObj.nodeType == Node.ELEMENT_NODE && selObj.tagName == "FORM")
  1341.     {
  1342.       formObj = selObj;
  1343.     }
  1344.     else
  1345.     {
  1346.       selObj = selObj.parentNode;
  1347.     }
  1348.   }
  1349.   
  1350.   return formObj;
  1351. }
  1352.  
  1353. //--------------------------------------------------------------------
  1354. // FUNCTION:
  1355. //   toggleSubmitAsVisibility
  1356. //
  1357. // DESCRIPTION:
  1358. //   toggles the visibility of "Submit As: [menu]" that appears on 
  1359. //   the UI.  This menu should be visible for all items except text
  1360. //
  1361. // ARGUMENTS:
  1362. //   displayAs
  1363. //
  1364. // RETURNS:
  1365. //   Nothing
  1366. //--------------------------------------------------------------------
  1367.  
  1368. function toggleSubmitAsVisibility(displayAs)
  1369. {
  1370.   var currentVal = _SubmitAs.getValue();
  1371.  
  1372.   if ((displayAs != STATICTEXT) && (currentVal == " " || !currentVal))
  1373.   {
  1374.     // if any form field is chosen in displayAs menu
  1375.     
  1376.     var databaseType = MMDB.getDatabaseType(_ConnectionName.getValue());
  1377.  
  1378.     _SubmitAs.enable();
  1379.     _SubmitAs.del();
  1380.     _SubmitAs.pickValue(dwscripts.getDBColumnTypeAsString(ColumnTypes[_ColumnNames.getRowValue().column], databaseType));
  1381.   }
  1382.   else if (displayAs == STATICTEXT)
  1383.   {
  1384.     // if plain text was chosen in displayAs menu
  1385.     
  1386.     _SubmitAs.append(" ");
  1387.     _SubmitAs.disable();
  1388.   }
  1389. }
  1390.  
  1391. //--------------------------------------------------------------------
  1392. // FUNCTION:
  1393. //   toggleLabelVisibility
  1394. //
  1395. // DESCRIPTION:
  1396. //   toggles the visibility of "Label: [textfield]" that appears on
  1397. //   the UI.  This textfield should be visible for all items except 
  1398. //   hidden fields
  1399. //
  1400. // ARGUMENTS:
  1401. //   displayAs
  1402. //
  1403. // RETURNS:
  1404. //   Nothing
  1405. //--------------------------------------------------------------------
  1406.  
  1407. function toggleLabelVisibility(displayAs)
  1408. {
  1409.   var labelFieldIsVisible = ( _ElementLabel.disabled != "true");
  1410.  
  1411.   if (displayAs != HIDDENFIELD && !labelFieldIsVisible)
  1412.   {
  1413.     // if non-hidden field & non-visible label field
  1414.     
  1415.     _ElementLabel.removeAttribute("disabled");
  1416.     _ElementLabel.setAttribute("value", _ColumnNames.getRowValue().label);
  1417.   }
  1418.   else if (displayAs == HIDDENFIELD && labelFieldIsVisible)
  1419.   {
  1420.     // if hidden field
  1421.     
  1422.     _ElementLabel.setAttribute("value", "");
  1423.     _ElementLabel.setAttribute("disabled", "true");
  1424.   }
  1425. }
  1426.  
  1427. //--------------------------------------------------------------------
  1428. // FUNCTION:
  1429. //   toggleSubmitAs
  1430. //
  1431. // DESCRIPTION:
  1432. //   toggles the visibility of "Submit As: [menu]" that appears on 
  1433. //   the UI.  This menu is disabled in case of Update form and if
  1434. //   it is a primary key column
  1435. //
  1436. // ARGUMENTS:
  1437. //   show - boolean 
  1438. //
  1439. // RETURNS:
  1440. //   Nothing
  1441. //--------------------------------------------------------------------
  1442.  
  1443. function toggleSubmitAs(bShow)
  1444. {
  1445.   if (bShow)
  1446.   { 
  1447.     _SubmitAs.enabled();
  1448.   }
  1449.   else
  1450.   {
  1451.     _SubmitAs.append(" ");
  1452.     _SubmitAs.disable();
  1453.   }
  1454. }
  1455.  
  1456. //--------------------------------------------------------------------
  1457. // FUNCTION:
  1458. //   EnableDisableUpDownBtns
  1459. //
  1460. // DESCRIPTION:
  1461. //   Enable/disables the elemUp and elemDown buttons
  1462. //
  1463. // ARGUMENTS:
  1464. //   None
  1465. //
  1466. // RETURNS:
  1467. //   Nothing
  1468. //--------------------------------------------------------------------
  1469.  
  1470. function EnableDisableUpDownBtns()
  1471. {
  1472.   if ((_ColumnNames.list.length <= 1) ||
  1473.       (_ColumnNames.getRowIndex() <= 0))
  1474.   {
  1475.     _ElemUp.setAttribute("disabled", true);
  1476.     _ElemUp.src = "../Shared/MM/Images/btnUp_dis.gif";   
  1477.   }
  1478.   else
  1479.   {
  1480.     _ElemUp.setAttribute("disabled", false);
  1481.     _ElemUp.src = "../Shared/MM/Images/btnUp.gif";      
  1482.   }
  1483.   
  1484.   if ((_ColumnNames.list.length <= 1) ||
  1485.       (_ColumnNames.getRowIndex() == (-1)) ||
  1486.       ((_ColumnNames.list.length - 1) == _ColumnNames.getRowIndex()))
  1487.   {
  1488.     _ElemDown.setAttribute("disabled", true);
  1489.     _ElemDown.src = "../Shared/MM/Images/btnDown_dis.gif";        
  1490.   }
  1491.   else
  1492.   {
  1493.     _ElemDown.setAttribute("disabled", false);
  1494.     _ElemDown.src = "../Shared/MM/Images/btnDown.gif";      
  1495.   }
  1496. }
  1497.  
  1498. //--------------------------------------------------------------------
  1499. // FUNCTION:
  1500. //   EnableDisableAddDelBtns
  1501. //
  1502. // DESCRIPTION:
  1503. //   Enable/disables the elemAdd and elemDel buttons
  1504. //
  1505. // ARGUMENTS:
  1506. //   None
  1507. //
  1508. // RETURNS:
  1509. //   Nothing
  1510. //--------------------------------------------------------------------
  1511.  
  1512. function EnableDisableAddDelBtns()
  1513. {
  1514.   // Check if there are any columns
  1515.   
  1516.   if (ColumnsToAdd.length == 0)
  1517.   {
  1518.     _ElemAdd.setAttribute("disabled", true);
  1519.     _ElemAdd.src = "../Shared/MM/Images/btnAdd_dis.gif";   
  1520.   }
  1521.   else
  1522.   {
  1523.     _ElemAdd.setAttribute("disabled", false);
  1524.     _ElemAdd.src = "../Shared/MM/Images/btnAdd.gif"; 
  1525.   }
  1526.     
  1527.   if ((_ColumnNames.list.length == 0) ||
  1528.       (_ColumnNames.getRowIndex() == (-1)))
  1529.   {
  1530.     _ElemDel.setAttribute("disabled", true);
  1531.     _ElemDel.src = "../Shared/MM/Images/btnDel_dis.gif";        
  1532.   }
  1533.   else
  1534.   {
  1535.     _ElemDel.setAttribute("disabled", false);
  1536.     _ElemDel.src = "../Shared/MM/Images/btnDel.gif";                
  1537.   }
  1538. }
  1539.  
  1540. //--------------------------------------------------------------------
  1541. // FUNCTION:
  1542. //   displayDynamicDataDialog
  1543. //
  1544. // DESCRIPTION:
  1545. //   pops up the dialog allowing the user to choose dynamic data
  1546. //
  1547. // ARGUMENTS:
  1548. //   textFieldObj
  1549. //
  1550. // RETURNS:
  1551. //   Nothing
  1552. //--------------------------------------------------------------------
  1553.  
  1554. function displayDynamicDataDialog(textFieldObj)
  1555. {
  1556.   var expression = dw.showDynamicDataDialog(textFieldObj.value);
  1557.  
  1558.   if (expression)
  1559.   {
  1560.     textFieldObj.value = expression;
  1561.   }
  1562. }
  1563.  
  1564. //--------------------------------------------------------------------
  1565. // FUNCTION:
  1566. //   populateFormFieldStorageType
  1567. //
  1568. // DESCRIPTION:
  1569. //   This function is called by updateUI function.  It is responsible
  1570. //   for populating the Column grid.
  1571. //
  1572. // ARGUMENTS:
  1573. //   rowValObj - Column Name
  1574. //   rsName - Column Type
  1575. //   colName  - Recordset Name
  1576. //
  1577. // RETURNS:
  1578. //   Array
  1579. //--------------------------------------------------------------------
  1580.  
  1581. function populateFormFieldStorageType(rowValObj, rsName, colName)
  1582. {
  1583.   // note: this fn is only called when the row is first created, which is why
  1584.   // it only lists some of the available form types
  1585.  
  1586.   var displayType = rowValObj.displayAs.type;
  1587.   var dynDataVal = createDynamicData(rsName, colName);
  1588.   
  1589.   rowValObj.defaultStr = dynDataVal;
  1590.  
  1591.   if (displayType == "textField" || 
  1592.       displayType  == "textArea" || 
  1593.       displayType  == "hiddenField")
  1594.   {
  1595.     rowValObj.displayAs.value = dynDataVal;
  1596.   }
  1597.   else if (displayType == "text")
  1598.   {
  1599.     rowValObj.displayAs.text = dynDataVal;
  1600.   }
  1601.   else if (displayType == "dynamicCheckBox")
  1602.   {
  1603.     rowValObj.displayAs.checkIf = dynDataVal;
  1604.   }
  1605.  
  1606.   return rowValObj;
  1607. }
  1608.  
  1609. //--------------------------------------------------------------------
  1610. // FUNCTION:
  1611. //   createDynamicData
  1612. //
  1613. // DESCRIPTION:
  1614. //   Pops up the dialog allowing the user to choose dynamic data
  1615. //
  1616. // ARGUMENTS:
  1617. //   rs - Recordset
  1618. //   col - Column Name
  1619. //
  1620. // RETURNS:
  1621. //   String
  1622. //--------------------------------------------------------------------
  1623.  
  1624. function createDynamicData(rs, col)
  1625. {
  1626.   var retVal = "";
  1627.  
  1628.   var retVal = "";
  1629.   if (rs){
  1630.     var colArray = dwscripts.getFieldNames(rs);
  1631.     if (dwscripts.findInArray(colArray, col) != -1){
  1632.       var paramObj = new Object();
  1633.       paramObj.sourceName = rs;
  1634.       paramObj.bindingName = col;
  1635.  
  1636.       retVal = extPart.getInsertString("", "Recordset_DataRef", paramObj);
  1637.     }
  1638.   }
  1639.   return retVal;
  1640. }
  1641.  
  1642. //--------------------------------------------------------------------
  1643. // FUNCTION:
  1644. //   updateDefaultFormFieldValues
  1645. //
  1646. // DESCRIPTION:
  1647. //   Goes through the default values, and replace references to the old
  1648. //   recordset with the new recordset
  1649. //
  1650. // ARGUMENTS:
  1651. //   oldRS - old Recordset
  1652. //   newRS - new Recordset
  1653. //
  1654. // RETURNS:
  1655. //   Nothing
  1656. //--------------------------------------------------------------------
  1657.  
  1658. function updateDefaultFormFieldValues(oldRS, newRS)
  1659. {
  1660.   var rowObjs = _ColumnNames.valueList;
  1661.   var nRows = rowObjs.length, i, fieldType, currRowObj, regExp;
  1662.  
  1663.   for (i = 0; i < nRows; i++)
  1664.   {
  1665.     currRowObj = rowObjs[i];
  1666.     regExp = new RegExp(oldRS,"g");
  1667.     currRowObj.defaultStr = currRowObj.defaultStr.toString().replace(regExp, newRS);
  1668.     currRowObj.passwordStr = currRowObj.passwordStr.toString().replace(regExp, newRS);
  1669.  
  1670.     // update the current display
  1671.  
  1672.     switch (currRowObj.displayAs.type)
  1673.     {
  1674.       case "textField":
  1675.       case "textArea":
  1676.       case "hiddenField":
  1677.         currRowObj.displayAs.value = currRowObj.defaultStr;
  1678.         break;
  1679.       case "passwordField":
  1680.         currRowObj.passwordField.value = currRowObj.passwordStr;
  1681.         break;
  1682.       case "text":
  1683.         currRowObj.displayAs.text = currRowObj.defaultStr;
  1684.         break;
  1685.       case "radioGroup":
  1686.       case "dynamicRadioGroup":
  1687.         currRowObj.displayAs.defaultChecked = currRowObj.defaultStr;
  1688.         break;
  1689.       case "menu":
  1690.       case "dynamicMenu":
  1691.         currRowObj.displayAs.defaultSelected = currRowObj.defaultStr;
  1692.         break;
  1693.       case "dynamicCheckBox":
  1694.         currRowObj.displayAs.checkIf = currRowObj.defaultStr;
  1695.         break;
  1696.       case "default":
  1697.         break;  
  1698.     }
  1699.   } 
  1700. }
  1701.  
  1702. //--------------------------------------------------------------------
  1703. // FUNCTION:
  1704. //   sortByPrimaryKeyCB
  1705. //
  1706. // DESCRIPTION:
  1707. //   Sort such that columns that are primary keys are at the end.
  1708. //
  1709. // ARGUMENTS:
  1710. //   a, b: columnValueNodes.
  1711. //
  1712. // RETURNS:
  1713. //   If -1 is returned: order stays the same, if 1: values are switched, if 0: values are equal
  1714. //--------------------------------------------------------------------
  1715.  
  1716. function sortByPrimaryKeyCB(a, b)
  1717. {
  1718.   return (a.getIsPrimaryKey() && !b.getIsPrimaryKey()) ? 1 : (-1);
  1719. }
  1720.